package org.example;

import javax.servlet.*;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 实现接口
 * 作用：
 *     1.接收请求（数据）
 *     2.调用业务方法（增删改查）
 *     3.
 */
public class MyServlet implements Servlet {
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        //接受请求
        //浏览器内输入localhost:9527/myservlet?param=张三 调用接口，传参 终端返回张三
        String param = servletRequest.getParameter("param");
        System.out.println(param);

        //响应数据
        //中文显示
        servletResponse.setContentType("text/html;charset=UTF-8");
        //在浏览器显示
        PrintWriter writer = servletResponse.getWriter();
        writer.write("你好，"+param+"请求已收到");
        //浏览器打印标题模式  jsp
        writer.write("<h1>你好哈哈哈<h1>");
        writer.flush();
        writer.close();


    }

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }


    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
